package com.kaifamiao.io.d0923;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {

    public static void main(String[] args) {
        Class<Student> studentClass = Student.class;

        try {
            // 创建对象, 无参构造存在并可访问
//            Student stu = studentClass.newInstance();

            Constructor<Student> constructor = studentClass.getDeclaredConstructor(String.class);

            Student student = constructor.newInstance("zhangsan");
            System.out.println(student);

        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }


    }
}
